#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using WaveMaster.Holidays.Club.Service;
using WaveMaster.Holidays.Club.Domain;
using System.Configuration;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
using System.Collections;

#endregion

namespace WaveMaster.Holidays.Club.Web
{
    public partial class UserControlReportPassenger : UserControl
    {
        TravelAgentService m_travelAgentService;
        SeaPortService m_SeaPortService;
        CheckInService m_bookingService;
        VesselService m_vesselService;

        User m_currentUser;
        MainForm m_mainForm;

        public UserControlReportPassenger(string name, User user, MainForm mainForm)
        {
            InitializeComponent();
            Name = name;
            m_currentUser = user;
            m_mainForm = mainForm;
            m_travelAgentService = (TravelAgentService)ServiceFactory.Instance().GetService(ServiceFactory.TRAVEL_AGENT_SERVICE);
            m_SeaPortService = (SeaPortService)ServiceFactory.Instance().GetService(ServiceFactory.SEAPORT_SERVICE);
            m_bookingService = (CheckInService)ServiceFactory.Instance().GetService(ServiceFactory.BOOKING_SERVICE);
            m_vesselService = (VesselService)ServiceFactory.Instance().GetService(ServiceFactory.VESSEL_SERVICE);

            initToolBarClick();
            initComboDataSource();
            comboBoxTravelAgent.Text = m_currentUser.TravelAgent.Name;
            comboBoxTravelAgent.Enabled = m_currentUser.UserType == UserType.Administrators;

        }

        private void initComboDataSource()
        {
            ArrayList tas = new ArrayList();
            tas.Add(new TravelAgent(0, "ALL"));
            tas.AddRange(m_travelAgentService.LoadAllTravelAgent());
            comboBoxTravelAgent.DataSource = tas;

            ArrayList sep = new ArrayList();
            sep.Add(new SeaPort(0, "ALL"));
            sep.AddRange(m_SeaPortService.LoadAllSeaPort());
            comboBoxSeaPort.DataSource = sep;

            ArrayList ves = new ArrayList();
            ves.Add(new Vessel(0, "ALL"));
            ves.AddRange(m_vesselService.LoadAllVessel());
            comboBoxVessel.DataSource = ves;

            ArrayList paxStatus = new ArrayList();
            paxStatus.Add("ALL");
            paxStatus.AddRange(Enum.GetValues(typeof(PassengerStatus)));
            comboBoxPaxStatus.DataSource = paxStatus;
        }

        private void initToolBarClick()
        {
            toolBarButtonRunReport.Click += new EventHandler(toolBarButtonRunReport_Click);
        }

        void toolBarButtonRunReport_Click(object sender, EventArgs e)
        {
            TravelAgent ta = (TravelAgent)comboBoxTravelAgent.SelectedValue;
            SeaPort s = (SeaPort)comboBoxSeaPort.SelectedValue;
            Vessel v = (Vessel)comboBoxVessel.SelectedValue;

            DataSet result = m_bookingService.ReportPassenger(comboBoxPaxStatus.Text, dateTimePickerFrom.Value, dateTimePickerTo.Value,
                ta.TravelAgentID, s.m_seaPortID, v.m_vesselID);
            result.WriteXml(ConfigurationManager.AppSettings["ReportDataTemp"] + "PassengerReport" + m_currentUser.UserID + ".xml", XmlWriteMode.WriteSchema);
            htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?ReportDataSource=PassengerReport" + m_currentUser.UserID + ".xml&ReportFile=PassengerReport.rpt";
            htmlBox1.Update();


            //result.WriteXml(@"D:\Others\Projects\WavemasterHolidaysClub\ReportBooking.xml", XmlWriteMode.WriteSchema);

            //string reportID = ServiceFactory.GenerateRandomID().ToString();
            //Session["ReportBookingData" + reportID] = result;
            //Session["ReportBookingFile" + reportID] = "BookingReport.rpt";
            //string param1 = "ReportFile=ReportBookingFile" + reportID;
            //string param2 = "ReportDataSource=ReportBookingData" + reportID;
            //htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?" + param1 + "&" + param2;
            ////htmlBox1.Url = "http://" + this.Context.HttpContext.Request.ServerVariables["SERVER_NAME"] + ":" + this.Context.HttpContext.Request.ServerVariables["SERVER_PORT"] + @"/Report/" + "ReportViewer.aspx?" + param1 + "&" + param2;
            //htmlBox1.Update();
        }
    }
}